<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>第四次课——css3D旋转立方体</title>
  <style>
    .spincube {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }

    .content {
      width: 200px;
      height: 200px;
      box-sizing: border-box;
      margin: 100px auto;
      position: relative;
      transform: rotateY(45deg) rotateX(45deg) rotateZ(45deg);
      transform-style: preserve-3d;
      animation: spin 5s infinite;
    }

    .surface {
      width: 200px;
      height: 200px;
      font-size: 60px;
      position: absolute;
      left: 0;
      top: 0;
    }

    .surface1 {
      background-color: rgba(255, 0, 0, 0.7);
      transform: translateX(-100px) rotateY(90deg);
    }

    .surface2 {
      background-color: rgba(255, 0, 0, 0.7);
      transform: translateX(100px) rotateY(90deg);
    }

    .surface3 {
      background-color: rgba(255, 255, 0, 0.7);
      transform: translateY(-100px) rotateX(90deg);
    }

    .surface4 {
      background-color: rgba(255, 255, 0, 0.7);
      transform: translateY(100px) rotateX(90deg);
    }

    .surface5 {
      background-color: rgba(0, 255, 255, 0.7);
      transform: translateZ(-100px) rotateZ(90deg);
    }

    .surface6 {
      background-color: rgba(0, 255, 255, 0.7);
      transform: translateZ(100px) rotateZ(90deg);
    }

    @keyframes spin {
      from {
        transform: rotateY(45deg) rotateX(45deg) rotateZ(45deg);
      }

      to {
        transform: rotateY(360deg) rotateX(45deg) rotateZ(45deg);
      }
    }

    @-webkit-keyframes spin {
      from {
        transform: rotateY(45deg) rotateX(45deg) rotateZ(45deg);
      }

      to {
        transform: rotateY(360deg) rotateX(45deg) rotateZ(45deg);
      }
    }

    /* 
          position:relative absolute
          父相子绝
          生成相对定位的元素，相对于其正常位置进行定位。
          生成绝对定位的元素，相对于 static 定位以外的第一个父元素进行定位。

          transform:
          https://www.runoob.com/cssref/css3-pr-transform.html
          translateX(x) 移动X/Y/Z轴的距离
          rotateX(angle) 绕着X/Y/Z轴的旋转 angle的值应该为deg结尾
          transform-style: preserve-3d; 转换为3D视图

          animation
          动画相关 值 动画名字 持续时间 重复次数
          @keyframes 动画名字{
              from{
                  开始值
              }to{
                  结束值
              }
          }

      */
  </style>
</head>

<body>
  <div class="spincube">
    <div class="content">
      <div class="surface surface1"></div>
      <div class="surface surface2"></div>
      <div class="surface surface3"></div>
      <div class="surface surface4"></div>
      <div class="surface surface5"></div>
      <div class="surface surface6"></div>
    </div>
  </div>
</body>

</html>